package grg.learn.compose.wanandroid.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import grg.learn.compose.wanandroid.data.model.IndexArticlePage
import grg.learn.compose.wanandroid.data.model.IndexBanner
import grg.learn.compose.wanandroid.data.repo.IndexRepository
import kotlinx.coroutines.flow.*

class MainViewModel(
    private val indexRepo: IndexRepository
) : ViewModel() {

    fun getIndexArticles(page: String): Flow<IndexArticlePage?> {
        return indexRepo.getIndexArticles(page)
            .shareIn(viewModelScope, SharingStarted.WhileSubscribed())
    }

    fun getBanners(): Flow<List<IndexBanner>> = indexRepo.getIndexBanners()
        .shareIn(viewModelScope, SharingStarted.WhileSubscribed())

}